﻿<template>
  <a-modal
    :title="title"
    width="30%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <!--<a-form-model-item label="更新时间" prop="UpdateTime">-->
        <!--  <a-input v-model="entity.UpdateTime" autocomplete="off" placeholder="更新时间" />-->
        <!--</a-form-model-item>-->
        <a-form-model-item label="客户编码" prop="cusCode">
          <a-input :disabled="true" v-model="entity.cusCode" autocomplete="off" placeholder="客户编码"/>
        </a-form-model-item>
        <a-form-model-item label="客户名称" prop="cCusName">
          <a-input :disabled="true" v-model="this.cCusName" autocomplete="off" placeholder="客户名称"/>
        </a-form-model-item>
        <a-form-model-item label="坏账金额" prop="baddebts">
          <a-input-number
            v-model="entity.baddebts"
            default-value="0"
            :step="0.1"
            :min="0"
            style="width:100%"
          />
        </a-form-model-item>
        <a-form-model-item label="备注" prop="Remark">
          <a-input v-model="entity.Remark" autocomplete="off" placeholder="备注"/>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      cCusName: '',
      rules: {},
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (record, title) {
      this.init()
      this.title = title
      if (record) {
        this.loading = true
        this.$http.post('/CustomerManagement/ar_baddebts/GetTheDataBycCusCode?cCusCode=' + record.cCusCode).then(resJson => {
          if (resJson.Success) {
            this.loading = false
            if (resJson.Data) {
              this.entity = resJson.Data
              this.cCusName = record.cCusName
            } else {
              this.entity.cusCode = record.cCusCode
              this.cCusName = record.cCusName
            }
          }
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/CustomerManagement/ar_baddebts/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
